
import goodCartApi from '@/api/goodCartApi';

export default {
    state: {
        cartList: []
    },
    mutations: {
        init(state, data) {
            state.cartList = data;
        },
        del(state, gid) {

        }
    }, actions: {
        getCartList({ commit },{uid}) {
            console.log("uid===",uid);
            return new Promise((resolve,reject)=>{
                goodCartApi.getCartlist(uid).then(res=>{
                    resolve(res);
                }).catch(error =>{
                    reject(error);
                })
            })
        },
        addGood({ commit }, good) {
            console.log(good);
            return new Promise((resolve,reject) => {
                goodCartApi.addGoodCart(good).then(res =>{
                    resolve(res);
                }).catch(error =>{
                    reject(error);
                })
            })
        },
        editNum({ commit },{_id,type}) {
            console.log(_id,type);
            return new Promise((resolve,reject)=>{
                goodCartApi.updateCartNum(_id,type).then(res=>{
                    resolve(res);
                }).catch(error =>{
                    reject(error);
                })
            })
        }
    }
}